Filter the current package out of override paths
authorAlex Crichton <alex@alexcrichton.com>
Wed, 23 Jul 2014 15:49:02 +0000 (08:49 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 23 Jul 2014 15:52:27 +0000 (08:52 -0700)
The current package being built should never be overridden, only its
dependencies.

Closes #225

src/cargo/ops/cargo_compile.rs
tests/test_cargo_compile_path_deps.rs

index 26cb33d217d8e8b0d9d234a534dab3c74a38966a..a6f894d0cebaff60aafa8f5f27b96c473997f456 100644 (file)
@@ -60,7 +60,8 @@ pub fn compile(manifest_path: &Path,
     }
 
     let user_configs = try!(config::all_configs(os::getcwd()));
-    let override_ids = try!(source_ids_from_config(&user_configs));
+    let override_ids = try!(source_ids_from_config(&user_configs,
+                                                   manifest_path.dir_path()));
     let source_ids = package.get_source_ids();
 
     let (packages, resolve) = {
@@ -107,8 +108,8 @@ pub fn compile(manifest_path: &Path,
     Ok(test_executables)
 }
 
-fn source_ids_from_config(configs: &HashMap<String, config::ConfigValue>)
-                          -> CargoResult<Vec<SourceId>> {
+fn source_ids_from_config(configs: &HashMap<String, config::ConfigValue>,
+                          cur_path: Path) -> CargoResult<Vec<SourceId>> {
     debug!("loaded config; configs={}", configs);
 
     let config_paths = configs.find_equiv(&"paths").map(|v| v.clone());
@@ -118,7 +119,13 @@ fn source_ids_from_config(configs: &HashMap<String, config::ConfigValue>)
         internal("invalid configuration for the key `path`")
     }));
 
-    Ok(paths.iter().map(|p| SourceId::for_path(&Path::new(p.as_slice()))).collect())
+    // Make sure we don't override the local package, even if it's in the list
+    // of override paths
+    Ok(paths.iter().filter(|p| {
+        cur_path != os::make_absolute(&Path::new(p.as_slice()))
+    }).map(|p| {
+        SourceId::for_path(&Path::new(p.as_slice()))
+    }).collect())
 }
 
 fn scrape_target_config(config: &mut Config,
index d1d7b06c13511cb2a5a96605347ffb3af16225e9..3d73e809ced06389d794f82e4f34e7d580a48391 100644 (file)
@@ -505,3 +505,39 @@ test!(error_message_for_missing_manifest {
                                      p.root().join_many(&["src", "bar"]).display())));
 
 })
+
+test!(override_self {
+    let bar = project("bar")
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "bar"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+        "#)
+       .file("src/lib.rs", "");
+
+    let p = project("foo");
+    let root = p.root().clone();
+    let p = p
+        .file(".cargo/config", format!(r#"
+            paths = ['{}']
+        "#, root.display()))
+        .file("Cargo.toml", format!(r#"
+            [package]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.bar]
+            path = '{}'
+
+        "#, bar.root().display()))
+       .file("src/lib.rs", "")
+       .file("src/main.rs", "fn main() {}");
+
+    bar.build();
+    assert_that(p.cargo_process("cargo-build"), execs().with_status(0));
+
+})